//------------------------------------------------------------------------------
#include "CMyTextEdit.h"
//------------------------------------------------------------------------------
CMyTextEdit::CMyTextEdit(QWidget *parent) : QTextEdit(parent), CChampText()
{
	setTabChangesFocus(true);
	setDataType(CCommun::edtString);
}
//------------------------------------------------------------------------------
QString CMyTextEdit::getValue(void)
{
	QString ret=toPlainText().replace("\"", "\\\"").trimmed();
	return ret;
}
//------------------------------------------------------------------------------
void CMyTextEdit::setValue(QVariant value)
{
	QString text=value.toString().replace("\\\"", "\"");
	setPlainText(toString(QVariant(text)));
}
//------------------------------------------------------------------------------
void CMyTextEdit::setStateEnable(bool enable)
{
	if(_standaloneEnable)
	{
		setEnabled(enable);
	}
}
//------------------------------------------------------------------------------
void CMyTextEdit::setAttribut(EAttribut value)
{
	QString styleSheet="color: %1; font-weight: %2; selection-background-color: %3;";
	QString color="black";
	QString weight="normal";
	QString selectionColor="#678DB2";
	
	_attribut=value;
	
	if(value & atObligatoire)
	{
		selectionColor="#678DB2";
		color="#FF6464";
		weight="bold";
	}
	if(value & atObligatoireConditionel)
	{
		selectionColor="#FF6464";
		color="#6464FF";
		weight="bold";
		setToolTip(getTextCondition());
	}
	
	setStyleSheet(styleSheet.arg(color).arg(weight).arg(selectionColor));
}
//------------------------------------------------------------------------------
void CMyTextEdit::setTextCondition(QString value)
{
	_textCondition=value;
	if(getAttribut() & atObligatoireConditionel)
	{
		setToolTip(value);
	}
}
//------------------------------------------------------------------------------
bool CMyTextEdit::isEmpty(void)
{
	return toBool(toPlainText());
}
//------------------------------------------------------------------------------
void CMyTextEdit::keyPressEvent(QKeyEvent * event)
{
	if(event->key() == Qt::Key_F1)
	{
		emit invokeHelp(this);
	}
	QTextEdit::keyPressEvent(event);
}
//------------------------------------------------------------------------------
